﻿using KTD.Web.BLL;
using KTD.Web.Models.VD;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using XXS.Common;
using XXS.Common.ControllerExt;

namespace KTD.Web.Controllers
{
    public class CommentController : Controller
    {
        public ActionResult Index(CommentQD im)
        {
          
            var res = MF.CommentManager.GetListBy(im);
            res.Action = "Index";
            res.ControllerContext = this.ControllerContext;
            return View(res);
        }

        public ActionResult Detail(int Id)
        {

            ViewBag.Id = Id;
            var res = MF.CommentManager.Find(Id);
            return View(res);
        }


        [HttpPost]
        public ActionResult Create(CommentCD im)
        {

            MF.CommentManager.Create(im);
            return this.JsonNet(new { success = true });
        }

        [HttpGet]
        public ActionResult Update(int Id)
        {
            var model = MF.CommentManager.Find(Id);
            return View(model);
        }


        public ActionResult Delete(int Id)
        {
            try
            {
                MF.CommentManager.Delete(Id);
                return this.JsonNet(new { success = true });
            }
            catch (Exception ex)
            {
                return this.JsonNet(new { success = false, msg = ex.Message });
            }
        }


        public ActionResult Find(int Id)
        {
            try
            {
                var res = MF.CommentManager.Find(Id);
                return this.JsonNet(new { success = true, data = res }, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                return this.JsonNet(new { success = false, msg = ex.Message }, JsonRequestBehavior.AllowGet);
            }
        }

     

        public ActionResult GetList()
        {
            try
            {
                var res = MF.CommentManager.GetListBy(new CommentQD() { PageSize = 40 });
                return this.JsonNet(res.PageData.ToExtGrid(), JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                return this.JsonNet(new { success = false, msg = ex.Message }, JsonRequestBehavior.AllowGet);
            }
        }
    }
}